﻿using System;
using System.Collections.Generic;
using System.Threading;

namespace Klinkby.Scheduler
{
    /// <summary>
    /// Basic <see cref="IScheduledTask"/>
    /// </summary>
    [Serializable]
    public class ScheduledTask : MarshalByRefObject, IScheduledTask
    {
        readonly ThreadStart _command;
        readonly IInterval _interval;

        public ScheduledTask(ThreadStart command, IInterval interval)
        {         
            if (command == null)
                throw new ArgumentNullException("command");
            if (interval == null)
                throw new ArgumentNullException("interval");
            _command = command;
            _interval = interval;
        }

        #region IScheduledTask Members

        public void Execute()
        {
            _command();
        }

        public IInterval Interval
        {
            get 
            { 
                return _interval; 
            }
        }

        #endregion
    }
}
